package com.yanqu.road.server.manager.activity.climbtower;

import com.yanqu.road.dao.impl.activity.climbtower.ClimbTowerConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.climbtower.ClimbTowerTopInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description
 * @Author hyx
 * @Data 2022/09/07 10:00
 */
public class CrossClimbTowerConfigMgr {

    private static Logger logger = LogManager.getLogger(CrossClimbTowerConfigMgr.class.getName());

    private static Map<Integer, List<ClimbTowerTopInfo>> topConfigMap = new ConcurrentHashMap<>();

    public static synchronized void reloadConfig(int activityId) {
        topConfigMap.put(activityId, new ClimbTowerConfigDaoImpl().getClimbTowerTopInfoList(activityId));
    }

    public static synchronized void removeConfig(int activityId) {
        topConfigMap.remove(activityId);
    }

    public static List<ClimbTowerTopInfo> getTopConfigList(int activityId) {
        return topConfigMap.get(activityId);
    }

    public static ClimbTowerTopInfo getTopConfig(int activityId, int cellNum) {
        if (1 > cellNum ) {
            return null;
        }
        if (!topConfigMap.containsKey(activityId)) {
            return null;
        }
        List<ClimbTowerTopInfo> listInfo = topConfigMap.get(activityId);
        if (listInfo.size() < cellNum) {
            return null;
        }
        return topConfigMap.get(activityId).get(cellNum - 1);
    }
}
